import { _decorator, Component, Node } from 'cc';
import { ResManager } from './ResManager';
import { Constant } from '../Constant';
import { Global } from '../Global';
const { ccclass, property } = _decorator;

@ccclass('UIManager')
export class UIManager extends Component {
    private static _instance: UIManager;

    private uiMap: Map<string, Node> = new Map();

    static get instance() {
        if (!this._instance) {
            this._instance = new UIManager();
        }
        return this._instance;
    }

    public showUI(uiName: string) {
        if (this.uiMap.has(uiName)) {
            console.log(`${uiName} 已经打开`);
            return;
        }
        const ui = Global.getNode(Constant.PrefabUrl[uiName], Constant.ndUI);
        if (!ui) {
            console.error(`${uiName} 预制体不存在`);
            return;
        }
        this.uiMap.set(uiName, ui);
        ui.active = true;
    }

    public hideUI(uiName: string) {
        const ui = this.uiMap.get(uiName);
        if (ui) {
            ui.active = false;
            this.uiMap.delete(uiName);
        }
    }

}


